package springBoot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.core.JmsMessagingTemplate;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.jms.Queue;
import javax.jms.Topic;

/**
 * Created by lx on 2017/7/7.
 */
@Component
@EnableScheduling
public class Producer {
    @Autowired
    private Topic topic;
    @Autowired
    private Queue queue;
    @Autowired
    private JmsMessagingTemplate jmsMessagingTemplate;

    @Scheduled(fixedDelay = 5000) //定时器  5s执行一次
    public void send(){
        System.out.println("producer start ------------");
        jmsMessagingTemplate.convertAndSend(topic,"hello topic");
        jmsMessagingTemplate.convertAndSend(queue,"hello queue");
    }
}
